<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="com.gzsz.util.DBUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String patient_name = request.getParameter("patient_name");
    String doctor_name = request.getParameter("doctor_name");
    String order_date = request.getParameter("order_date");
    String order_type = request.getParameter("order_type");
    String order_detail = request.getParameter("order_detail");
    String execution_status = request.getParameter("execution_status");
    String execution_time = request.getParameter("execution_time");
    String remarks = request.getParameter("remarks");

    String id = request.getParameter("id");
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    try {
        DBUtil dbUtil = new DBUtil();
        // 1：加载驱动
//        Class.forName("com.mysql.cj.jdbc.Driver");
//        // 2：创建连接
//        String url = "jdbc:mysql://localhost:3306/medicald?serverTimezone=Asia/Shanghai";
//        String user = "root";
//        String password = "123456";
//        connection = DriverManager.getConnection(url, user, password);

        // 3：创建预编译命令对象
        // 假设表名为 patient，根据实际情况修改
        String sql = "INSERT INTO yizhu (patient_name, doctor_name, order_date, order_type, order_detail, execution_status,execution_time,remarks) " +
                "VALUES ('" + patient_name + "','" + doctor_name + "','" + order_date + "','" + order_type + "','" + order_detail + "','"+execution_status+"','" + execution_time + "','" + remarks + "');";

        // 4：执行命令对象，返回结果
        int i = dbUtil.executeUpdateBySQL(sql);
        if (i > 0) {
            response.sendRedirect("advice-addition.jsp");
        } else {
            out.println("插入失败");
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.println("发生错误：" + e.getMessage());
    } finally {
        // 关闭资源
        try {
            if (preparedStatement != null) preparedStatement.close();
            if (connection != null) connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
%>
